﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Infrastructure.Dto.Response.Common;

namespace WCS.Service.Instance
{
    public class BaseService
    {
        /// <summary>
        /// 接口返回对象
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public ApiResult GetResult(int? code = 0, string? message = "", object? data = null)
        {
            ApiResult result = new ApiResult()
            {
                code = ApiCode.ok,
                message = "ok",
                //操作成功
            };
            if (code <= 0)
            {
                result.code = ApiCode.fail;
                result.message = "fail";
                //操作失败
            }
            if (!string.IsNullOrEmpty(message))
            {
                result.message = message;
                //如果message里面没参数时返回默认参数ok或者fail
            }
            if (data != null)
            {
                result.data = data;
            }
            return result;
        }
    }
}
